package chapter05;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class AccountDaoImpl implements AccountDao {
	// 声明jdbcTemplate属性及其setter方法
		private JdbcTemplate jdbctemplate;

		public void setJdbcTemplate(JdbcTemplate jdbctemplate) {
			this.jdbctemplate = jdbctemplate;
		}
	@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,readOnly = false)
	public void transfer(String outUser, String inUser, int money) {
		this.jdbctemplate.update("update account set balance=balance+? where username=?",money,inUser);
		int i = 1/0;
		this.jdbctemplate.update("update account set balance=balance-? where username=?",money,outUser);
	}

}
